#include "NxFile.h"


int NJGIS::SERVICE::NjLocalFiles::getCount()
{
	return this->_mFiles.size();
}

int NJGIS::SERVICE::NjLocalFiles::getIterByIndex( int index, std::map<std::string, std::string>::iterator &iter )
{
	if(index > this->_mFiles.size())
	{
		return -2;
	}
	int localIndex = 0;
	for(iter = this->_mFiles.begin(); iter != this->_mFiles.end(); ++iter )
	{
		if(localIndex == index)
		{
			return 1;
		}
		localIndex++;
	}
	return -1;
}

const char* NJGIS::SERVICE::NjLocalFiles::getName( int index )
{
	std::map<std::string, std::string>::iterator iter;
	if(this->getIterByIndex(index, iter) == 1)
	{
		return iter->first.c_str();
	}
	return NULL;
}

const char* NJGIS::SERVICE::NjLocalFiles::getPath( int index )
{
	std::map<std::string, std::string>::iterator iter;
	if(this->getIterByIndex(index, iter) == 1)
	{
		return iter->second.c_str();
	}
	return NULL;
}

const char* NJGIS::SERVICE::NjLocalFiles::getPath( const char* name )
{
	std::map<std::string, std::string>::iterator iter = this->_mFiles.find(name);
	if (iter != this->_mFiles.end())
	{
		return iter->second.c_str();
	}
	return NULL;
}

int NJGIS::SERVICE::NjLocalFiles::insertFile( const char* name, const char* path )
{
	this->_mFiles.insert(std::pair<std::string, std::string>(name, path));
	return 1;
}

NJGIS::SERVICE::INjLocalFiles* NJGIS::SERVICE::NjFileHelper::createLocalFiles()
{
	return new NJGIS::SERVICE::NjLocalFiles();
}
